<!DOCTYPE html>
<html>

{include file='public/header'}

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="javascript:void(0)">首页</a>
            <a href="javascript:void(0)">分销</a>
            <a><cite>分销结算</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" id="reload" title="刷新">
            <i class="layui-icon" style="line-height:30px"><i class="iconfont">&#xe6aa;</i></i>
        </a>
    </div>
    <div class="x-body">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">结算状态：</label>
                    <div class="layui-input-inline">
                        <select name="status" id="">
                            <option value="">请选择</option>
                            <option value="1">待结算</option>
                            <option value="2">结算中</option>
                            <option value="3">已结算</option>
                        </select>
                    </div>
                </div>
                <button class="layui-btn" style="margin-left: 10px;" lay-submit lay-filter="searchList">搜索</button>
                <button type="reset" id="resetList" class="layui-btn layui-btn-primary">重置</button>
            </form>
        </div>
        <table id="distributionSettlementList" lay-filter="distributionSettlementList"></table>
    </div>
    <script type="text/html" id="tbBar">
        {{#  if(d.status === 1 ){ }}
            <a class="layui-btn layui-btn-xs" lay-event="settlement">申请结算</a>
        {{#  } else { }}
            <a class="layui-btn layui-btn-xs layui-btn-disabled">申请结算</a>
        {{#  } }}
    </script>
    <script>
        let params = {
            elem: '#distributionSettlementList'
            , toolbar: true
            , url: '/cps/distribution/distributionSettlementList' //数据接口
            , id: 'distributionSettlementList'
            , page:true
            , limit:15
            , cols: [[ //表头
                { field: 'id', title: 'ID', width: 70, align:'center' }
                , { field: 'name', title: '分销商名称', align:'center' }
                , { title: '结算日期', align:'center' , width:200, templet:function(d){
                    return `${d.start_date}至${d.end_date}`
                }}
                , { field: 'settlement_price', title: '结算金额', width:90, align:'center' }
                , { field: 'status', title: '结算状态', align:'center', width:90 ,templet:function(d){
                    let status = ''
                    switch (d.status) {
                        case 1:
                            status = '待结算'
                            break;
                        case 2:
                            status = '结算中'
                            break;
                        case 3:
                            status = '已结算'
                            break;
                    }
                    return status
                }}
                , { field: 'tax_rate', title: '增值税率', width:90 , align:'center' }
                , { field: 'payment_method', title: '收款方式', width:100 ,align:'center',templet:function(d){
                    return d.payment_method === 1 ? '银行卡对公' : '银行卡对私'
                } }
                , { field: 'payee', title: '收款人', width:100, align:'center' }
                , { field: 'collection_account', title: '收款账号', width:250, align:'center' }
                , { field: 'bank_name', title: '开户行',width:220, align:'center' }
                , { field: 'payment_time', title: '打款时间', width:170 ,align:'center', templet: function (d) {
                        return dayjsFormat(d.payment_time)
                    } 
                }
                , { toolbar: '#tbBar', title: '操作', align: 'center', width: 100}
            ]]
        }
        tableList(params)

        layui.use('table', function () {
            var table = layui.table;
            table.on('tool(distributionSettlementList)', function (obj) {
                var event = obj.event;
                if (event === 'settlement') {
                    AnyAjax('确定要结算此订单吗？','/cps/distribution/submitSettlementApply',{ id: obj.data.id },'distributionSettlementList')
                }
            });

        });
    </script>
</body>

</html>